package org.lex.swing;

import java.util.Arrays;

import javax.swing.JOptionPane;

public enum OptionType {
	YES_NO_OPTION(JOptionPane.YES_NO_OPTION, Option.YES, Option.NO),

	OK_CANCEL_OPTION(JOptionPane.OK_CANCEL_OPTION, Option.YES, Option.CANCEL) {
		public String[] getOptionDiaplayNames() {
			return new String[] { "OK", Option.CANCEL.getDisplayName() };
		}
	},

	YES_NO_CANCEL_OPTION(JOptionPane.YES_NO_CANCEL_OPTION, Option.YES, Option.NO, Option.CANCEL) {
		public int getOptionCount() {
			return 3;
		}
	};

	public static OptionType parseJOptionPaneType(int type) {
		switch (type) {
		case JOptionPane.YES_NO_OPTION:
			return OptionType.YES_NO_OPTION;
		case JOptionPane.YES_NO_CANCEL_OPTION:
			return OptionType.YES_NO_CANCEL_OPTION;
		case JOptionPane.OK_CANCEL_OPTION:
			return OptionType.OK_CANCEL_OPTION;
		default:
			return OptionType.YES_NO_CANCEL_OPTION;
		}
	}

	public static OptionType getDefaultOptionTyle() {
		return OptionType.YES_NO_CANCEL_OPTION;
	}

	public int getOptionCount() {
		return 2;
	}

	public int getOptionType() {
		return this.type;
	}

	public Option[] getOptions() {
		return Arrays.copyOf(options, options.length);
	}

	public String[] getOptionDiaplayNames() {
		String[] names = new String[options.length];
		for (int i = 0; i < options.length; i++)
			names[i] = options[i].getDisplayName();
		return names;
	}

	// =================================================
	private int type = JOptionPane.YES_NO_CANCEL_OPTION;
	private Option[] options = null;

	private OptionType(int type, Option... options) {
		this.type = type;
		this.options = options;
	}
}
